﻿Public Class frmCuotasPrestamo
    Dim utilidades As New Utilidades
    Dim _idSolicitud As String

    Public Sub New(ByVal idSolicitud As String)
        Me.InitializeComponent()
        _idSolicitud = idSolicitud
    End Sub

    Private Sub frmCuotasPrestamo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myAccesoDatos As New AccesoDatos
        Dim tabla As Data.DataTable
        Dim myConsulta As String
        myConsulta = "SELECT P.ID AS NRO_PRESTAMO, CONVERT(VARCHAR(10), P.FECHA_OTORGAMIENTO, 103) AS FECHA_OTORGAMIENTO, "
        myConsulta = myConsulta & "CONVERT(int, floor(S.MONTO)) AS MONTO, S.CANTIDAD_CUOTAS "
        myConsulta = myConsulta & "FROM PRESTAMOS P INNER JOIN CUOTAS C ON (P.ID = C.ID_PRESTAMO) "
        myConsulta = myConsulta & "INNER JOIN SOLICITUDES_PRESTAMOS S ON (P.ID_SOLICITUD = S.ID) "
        myConsulta = myConsulta & "WHERE P.ID_SOLICITUD = " & _idSolicitud
        tabla = myAccesoDatos.ejecutarConsulta(myConsulta)

        Me.txtNroPrestamo.Text = Convert.ToString(tabla.Rows.Item(0).Item(0))
        Me.txtOtorgamiento.Text = Convert.ToString(tabla.Rows.Item(0).Item(1))
        Me.txtMonto.Text = Convert.ToString(tabla.Rows.Item(0).Item(2))
        Me.txtCuotas.Text = Convert.ToString(tabla.Rows.Item(0).Item(3))


        myConsulta = "SELECT C.NRO_CUOTA, CONVERT(varchar(10), CONVERT(money, C.MONTO)) AS VALOR, CONVERT(VARCHAR(10), C.FECHA_VENCIMIENTO, 103) AS FECHA_VENCIMIENTO "
        myConsulta = myConsulta & "FROM PRESTAMOS P INNER JOIN CUOTAS C ON (P.ID = C.ID_PRESTAMO) "
        myConsulta = myConsulta & "INNER JOIN SOLICITUDES_PRESTAMOS S ON (P.ID_SOLICITUD = S.ID) "
        myConsulta = myConsulta & "WHERE P.ID_SOLICITUD = " & _idSolicitud
        myConsulta = myConsulta & " ORDER BY C.NRO_CUOTA"

        tabla = myAccesoDatos.ejecutarConsulta(myConsulta)
        gridCuotasPrestamos.DataSource = tabla
    End Sub

    Private Sub cmdAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAceptar.Click
        Me.Close()
    End Sub
End Class